package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.HolidaySettings;
import com.ruoyi.system.service.IHolidaySettingsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 节假日设置Controller
 * 
 * @author yuan
 * @date 2022-09-25
 */
@RestController
@RequestMapping("/system/holidaySettings")
public class HolidaySettingsController extends BaseController
{
    @Autowired
    private IHolidaySettingsService holidaySettingsService;

    /**
     * 查询节假日设置列表
     */
    @PreAuthorize("@ss.hasPermi('system:holidaySettings:list')")
    @GetMapping("/list/{year}/{month}")
    public AjaxResult list(@PathVariable("year") Integer year,@PathVariable("month") Integer month)
    {
        String str = "";
        if(month < 10){
           str = year + "-0" + month;
        }else{
            str = year + "-" + month;
        }
        List<HolidaySettings> list = holidaySettingsService.selectHolidaySettingsListByTime(str);
        return AjaxResult.success(list);
    }

    /**
     * 获取节假日设置详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:holidaySettings:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(holidaySettingsService.selectHolidaySettingsById(id));
    }

    /**
     * 保存节假日设置
     */
    @Log(title = "节假日设置", businessType = BusinessType.UPDATE)
    @PreAuthorize("@ss.hasPermi('system:holidaySettings:saveHolidayName')")
    @PostMapping("/saveHolidayName")
    public AjaxResult add(@RequestBody HolidaySettings holidaySettings)
    {
        return toAjax(holidaySettingsService.saveHolidaySettings(holidaySettings));
    }

}
